home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: reply.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "io.h"
- #include "list.h"
- #include "tid.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "bitvec.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "msgvector.h"
- #include "msg_funcs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "msg_globals.h"
- #include "log_globals.h"
- #include "server_util_funcs.h"
-
-
-
- int
- reply (
-
- int error,
- int code,
- int vecCount,
- BOOL taskDie
- )
- {
- /*
- * NOTE: this function builds the reply on the original message. This
- * is required so that routines like cl_ReadPage can fill
- * in information for the reply into the message body.
- * It is assumed that parts of the original
- * message.header are intact, in particular, replyRequested.
- * There are 2 exceptions: esmBADMESSAGEMAGIC and esmPROTOCOLVERSION.
- * In these 2 cases, we build a "legit" message from scratch (even though
- * the client might not understand it!),
- * after which we close the link.
- */
-
- register TCB *tcb;
-
-
- TRPRINT(TR_MSG, TR_LEVEL_1,
- ("thread:%d replying on link:%d code:%d vecCount:%d",
- Active->id, Active->linkId, code, vecCount));
-
- /*
- * get a register pointer to this thread
- */
- tcb = Active;
-
- if(error == esmNOERROR) {
- /* the client ignores the errno part if it's not a failure */
- code = esmNOERROR;
- } else {
- SM_ASSERT(LEVEL_3, ((error == esmFAILURE)&&(code != esmNOERROR)));
- }
-
- if(code == esmBADMESSAGEMAGIC || code == esmPROTOCOLVERSION) {
- tcb->message.header.replyRequested = TRUE;
- tcb->message.header.version = MESSAGE_VERSION;
- tcb->message.header.type = ERROR_REPLY;
- }
-
- if(tcb->message.header.replyRequested == TRUE) {
- { /* message statistics */
- int messageType;
- messageType = tcb->message.header.type;
- SM_ASSERT(LEVEL_1, ((messageType > 0) &&
- (messageType <= MAX_MSG_NUMBER)));
- /* no-reply-requested case is counted on INCOMING messages! */
- if(error == esmNOERROR)
- MsgStats.replied_ok[messageType] ++;
- else
- MsgStats.replied_in_error[messageType] ++;
- }
-
-
- #if TRACING IS_ENABLED
- {
- register int i;
-
- for (i = 0; i < vecCount; i++) {
- TRPRINT(TR_MSG, TR_LEVEL_2,
- ("vector:%d count:%d", i, tcb->iovec[i].iov_len));
- }
- }
- #endif
-
- /*
- * fill in the errno and the current end of the log
- */
- tcb->message.header.params.out.errno = code;
- tcb->message.header.params.out.endOfLog = OpenLog.nextValidLSN;
- tcb->message.header.params.out.linkTransError = Links[tcb->linkId].linkTransError;
-
- if(error == esmNOERROR) {
- SM_ASSERT(LEVEL_1,
- (LOG_PAGE_OFFSET(OpenLog.nextValidLSN.offset, (&OpenLog))!=0));
- }
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("first length:%d", tcb->iovec[0].iov_len));
-
- SM_ASSERT(LEVEL_3, vecCount <= MAX_IOVEC);
- if (writev(tcb->linkId, (struct iovec *) tcb->iovec, vecCount) < 0) {
-
- if ( (errno == EBADF) || (errno == EPIPE) ) {
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("bad socket:%d", tcb->linkId));
-
- /*
- * clear the link if it hasn't already been cleared
- */
- if( Links[tcb->linkId].linkClass == CL_CLIENT) {
- SM_ERROR(TYPE_LOG, errno);
- freeClientLink( &(Links[tcb->linkId]) );
- }
-
- /* check to see if this is a transaction thread */
- transThreadDeath(tcb);
-
- /*
- * check to see if the task should die
- */
- if (taskDie) {
-
- threadRestart();
-
- } else {
-
- return(esmFAILURE);
- }
-
- } else { /* errno neither EBADF or EPIPE */
-
- SM_ERROR(TYPE_FATAL, errno);
- }
- } /* end of writev */
- {
- register int i, totalBytes;
-
- for (totalBytes = 0, i = 0; i < vecCount; i++) {
- totalBytes += tcb->iovec[i].iov_len;
- }
- incPages(totalBytes, SENT, TRUE);
- }
- } /* end of replyRequested */
-
- /* check to see if this is a transaction thread */
- transThreadDeath(tcb);
-
- /*
- * restart this thread
- */
- if (taskDie) {
-
- TRPRINT(TR_MSG, TR_LEVEL_2, ("task restarting"));
- threadRestart();
-
- }
- return esmNOERROR;
- }
-